|
|
|
|
|
|
|
Solution 28
Drawing OLE Objects |
|
|
|
|
|
|
|
|
An object is a thing that exists somewhere in memory on either your system or another. An object variable contains a pointer to a location in local memory that contains an interfaceit's actually an array of pointers to functions, but as a VB programmer you don't have to worry about those implementation details. The only way to access an object is through this pointer to an interface. A given object can support many different interfaces. |
|
|
|
|
|
|
|
|
Figure S28-1:
Object variables point to a block of memory that
defines an interface |
|
|
|
|
|
|
|
|
When you declare different types of object variables, all you are really doing is specifying the type of interface pointer the variable holds. For example, a variable declared As Object always contains a pointer to an IDispatch interface. If you declare a variable as a certain type of class, that variable always contains a pointer to the native interface for that class. Remember, though, every interface is based on IUnknown, so if you have an object variable declared As IUnknown, it can contain a reference to any COM object regardless of the interface you are using. Figure S28-1 illustrates how an object variable points to an interface.1 |
|
|
|
|
|
|
|
|
Now let's look again at the C declaration and Visual Basic declaration for the OleDraw function: |
|
|
|
|
|
|
|
|
WINOLEAPI OleDraw( IUnknown * pUnk, //Pointer to the view object to be drawn
DWORD dwAspect, //How the object is to be represented
HDC hdcDraw, //Device context on which to draw
LPCRECT lprcBounds //Pointer to the rectangle in which the
//object is drawn
); Private Declare Function OleDraw Lib "ole32.dll" _
(pUnk As Object, ByVal dwAspect As Long , _
ByVal hdcDraw As Long, _
lprcBounds As RECT) As Long |
|
|
|
 |
|
 |
|
|
1 Again, I must stress that, without an understanding of COM, the preceding paragraph is probably incomprehensible. My book Developing COM/ActiveX Components with Visual Basic 6.0 will give you the necessary background. |
|
|
|
|
|